import { getModelInfo } from '@ve/utils/getModelInfo'
//必须带done回调 执行完成调用
export default function sendData({ vm, action, done }) {
  const moduleAId = action.extension.sendData.a && action.extension.sendData.a[0]
  const moduleBId = action.extension.sendData.b && action.extension.sendData.b[0]
  const sendKey = action.extension.getDataKey?.value || 'formData'
  const getKey = action.extension.sendDataKey.value
  console.log(action)
  // 查找模块信息
  let module_info_a = vm.vuiComponents[moduleAId].self
  let module_info_b = vm.vuiComponents[moduleBId].self
  if (module_info_b) {
    module_info_a['sendKey'] = sendKey
    module_info_b[getKey] = module_info_a[sendKey] || module_info_a['formData'] || module_info_a['getInfo']['data']['formData']
  }

  let model_info = getModelInfo(vm, moduleBId)
  if (model_info) {
    model_info['getKey'] = getKey
    model_info[getKey] = module_info_a[sendKey] || module_info_a['formData'] || module_info_a['getInfo']['data']['formData']
  }
  vm.$store.dispatch('preview/updateModelInfo', {
    moduleBId,
    modelInfo: model_info,
  })
  done(null, {})
}
